package services

import (
	"github.com/mlogclub/simple/sqls"
	"github.com/mlogclub/simple/web/params"

	"bbs-go/internal/models"
	"bbs-go/internal/repositories"
)

var CategoryService = newCategoryService()

func newCategoryService() *categoryService {
	return &categoryService{}
}

type categoryService struct {
}

func (s *categoryService) Get(id int64) *models.Category {
	return repositories.CategoryRepository.Get(sqls.DB(), id)
}

func (s *categoryService) Take(where ...interface{}) *models.Category {
	return repositories.CategoryRepository.Take(sqls.DB(), where...)
}

func (s *categoryService) Find(cnd *sqls.Cnd) []models.Category {
	return repositories.CategoryRepository.Find(sqls.DB(), cnd)
}

func (s *categoryService) FindOne(cnd *sqls.Cnd) *models.Category {
	return repositories.CategoryRepository.FindOne(sqls.DB(), cnd)
}

func (s *categoryService) FindPageByParams(params *params.QueryParams) (list []models.Category, paging *sqls.Paging) {
	return repositories.CategoryRepository.FindPageByParams(sqls.DB(), params)
}

func (s *categoryService) FindPageByCnd(cnd *sqls.Cnd) (list []models.Category, paging *sqls.Paging) {
	return repositories.CategoryRepository.FindPageByCnd(sqls.DB(), cnd)
}

func (s *categoryService) Create(t *models.Category) error {
	return repositories.CategoryRepository.Create(sqls.DB(), t)
}

func (s *categoryService) Update(t *models.Category) error {
	return repositories.CategoryRepository.Update(sqls.DB(), t)
}

func (s *categoryService) Updates(id int64, columns map[string]interface{}) error {
	return repositories.CategoryRepository.Updates(sqls.DB(), id, columns)
}

func (s *categoryService) UpdateColumn(id int64, name string, value interface{}) error {
	return repositories.CategoryRepository.UpdateColumn(sqls.DB(), id, name, value)
}

func (s *categoryService) Delete(id int64) {
	repositories.CategoryRepository.Delete(sqls.DB(), id)
}
